/**
 * title
 * @version  v1.0
 * @createTime: 2017/12/12 0012
 * @createAuthor LSZ
 * @updateHistory
 *                2017/12/12 0012  ashen   create
 */
import store from '@/vuex/store';
import mintUi from './mintUi';

const storePermission = (value, param) => { //门店类型权限
  if (store.state.shopAlter.store.storeCode) {
    if (param) {
      return param;
    }
    return true;
  } else {
    if (param) {
      return '';
    }
    return false;
  }
};

const permissions = (param) => { //角色权限与账号设置权限
  const permission = store.state.login.permission;
  const flag = permission.some(per => {
    return per.pageName === param;
  });
  if (!flag) {
    mintUi.openToast('您无该功能使用权限，请联系管理员');
  }
  return flag;
};

const hasPermissions = (param) => { //角色权限与账号设置权限
  const permission = store.state.login.permission;
  if (typeof (permission.some) === 'undefined') {
    return '';
  }
  const flag = permission.some(per => {
    return per.pageName === param;
  });
  if (flag) {
    return param;
  } else {
    return '';
  }
};
const thousandth = (str) => {
  if (!str) return '0';
  str = str + '';
  let reg = /\d(?=(?:\d{3})+(?:\.\d+|$))/g;
  return str.replace(reg, (...rest) => rest[0] + ',');
};
export {storePermission, permissions, hasPermissions, thousandth};
